import { createI18n } from "vue-i18n";

import { zh } from "./locales/zh";
import { en } from "./locales/en";

const message = {
  zh,
  en,
};
//nuxt3有自带的存储和获取cookie的方式
type MessageSchema = typeof zh;
export default defineNuxtPlugin((nuxtApp) => {
  const route = useRoute();
  const langages = useCookie("lang");
  const { lang = "zh" } = route.query;
  const i18n = createI18n<[MessageSchema], "zh" | "en">({
    legacy: false,
    globalInjection: true,
    fallbackLocale: "zh",
    // locale: (route.params && (route.params.en as string)) || "zh", //获取cookie值，默认为cn
    locale: lang as string,
    warnHtmlMessage: false,
    messages: message,
  });
  nuxtApp.vueApp.use(i18n);
});
